package com.yanfan.energybilling.controller;

import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.energybilling.domain.EnergrConfiguration;
import com.yanfan.energybilling.service.EnergrConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/energr/energrconfiguration")
public class EnergrConfigurationController extends BaseController {

    @Autowired
    private EnergrConfigurationService energrConfigurationService;

    @GetMapping("/list")
    public TableDataInfo selectByExample(Integer energyTpye,Integer dateTpye,String configurationName,Long configurationId) {
        startPage();
        List<EnergrConfiguration> energrConfigurations = energrConfigurationService.selectByExample(energyTpye,dateTpye,configurationName,configurationId);
        return getDataTable(energrConfigurations);
    }

    @GetMapping("/delete")
    public AjaxResult deleteEnergrConfiguration(Integer configurationId) {
        int i = energrConfigurationService.deleteEnergrConfiguration(configurationId);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @PostMapping("/add")
    public AjaxResult insert(@RequestBody EnergrConfiguration energrConfiguration) {
        int i = energrConfigurationService.insert(energrConfiguration);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @PostMapping("/update")
    public AjaxResult updateEnergrConfiguration(@RequestBody EnergrConfiguration energrConfiguration) {
        int i = energrConfigurationService.updateEnergrConfiguration(energrConfiguration);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
}
